package io.xccit.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.xccit.model.system.SysPost;
import io.xccit.model.vo.SysPostQueryVo;
import io.xccit.system.mapper.ISysPostMapper;
import io.xccit.system.service.ISysPostService;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;

/**
 * @author CH_ywx
 * @date 2023-06-28
 * @description
 */
@Service
public class SysPostServiceImpl extends ServiceImpl<ISysPostMapper, SysPost> implements ISysPostService {

    @Resource
    private ISysPostMapper sysPostMapper;

    /**
     * 条件分页查询
     * @param sysPostPage
     * @param sysPostQueryVo
     * @return
     */
    @Override
    public IPage<SysPost> selectPage(Page<SysPost> sysPostPage, SysPostQueryVo sysPostQueryVo) {
        LambdaQueryWrapper<SysPost> wrapper = new LambdaQueryWrapper<>();
        String name = sysPostQueryVo.getName();
        String postCode = sysPostQueryVo.getPostCode();
        Integer status = sysPostQueryVo.getStatus();
        if (!StringUtils.isEmpty(name)){
            wrapper.like(SysPost::getName,name);
        }
        if (!StringUtils.isEmpty(postCode)){
            wrapper.eq(SysPost::getPostCode,postCode);
        }
        if (status != null){
            wrapper.eq(SysPost::getStatus,status);
        }
        return sysPostMapper.selectPage(sysPostPage,wrapper);
    }
}
